import 'package:flutter/material.dart';
import 'package:dailypayagent/model/salescount.dart';
import 'package:dailypayagent/provider/provider_widget.dart';
import 'package:dailypayagent/provider/view_state_widget.dart';
import 'package:dailypayagent/ui/helper/refresh_helper.dart';
import 'package:dailypayagent/ui/widget/salescount_list_item.dart';
import 'package:dailypayagent/view_model/sale_model.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class SalsmanCount extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('业务员报表'),
        centerTitle: true,
      ),
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            color: Theme.of(context).backgroundColor,
            padding: const EdgeInsets.all(10),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  '查询月份',
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
                Text(
                  '查询月份',
                  style: TextStyle(
                    color: Colors.white,
                  ),
                ),
              ],
            ),
          ),
          Container(
            child: ProviderWidget<SalesCountModel>(
                model: SalesCountModel(),
                onModelReady: (model) => model.loadData(),
                builder: (context, model, child) {
                  if (model.isBusy) {
                    return Text('');
                  }
                  return Container(
                    color: Theme.of(context).accentColor,
                    padding: const EdgeInsets.all(30),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            Text(
                              '净收款金额',
                              style: TextStyle(
                                color: Colors.white,
                              ),
                            ),
                            SizedBox(height: 10),
                            Text(
                              model.salesCount.netreceipt.toString(),
                              style: TextStyle(
                                color: Colors.white,
                              ),
                            ),
                          ],
                        ),
                        Container(
                          height: 30,
                          child: VerticalDivider(
                            color: Colors.white60,
                          ),
                        ),
                        Column(
                          children: <Widget>[
                            Text(
                              '新增商户数(家)',
                              style: TextStyle(
                                color: Colors.white,
                              ),
                            ),
                            SizedBox(height: 10),
                            Text(
                              model.salesCount.newly.toString(),
                              style: TextStyle(
                                color: Colors.white,
                              ),
                            ),
                          ],
                        )
                      ],
                    ),
                  );
                }),
          ),
          Container(
            color: Colors.grey[200],
            padding: const EdgeInsets.all(10),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Text(
                  '业务员名称',
                  style: TextStyle(
                    color: Colors.grey,
                  ),
                ),
                Text(
                  '商户净收款',
                  style: TextStyle(
                    color: Colors.grey,
                  ),
                ),
                Text(
                  '新增商户数',
                  style: TextStyle(
                    color: Colors.grey,
                  ),
                ),
              ],
            ),
          ),
          Expanded(
            child: Container(
              child: ProviderWidget<SalesCountModel>(
                model: SalesCountModel(),
                onModelReady: (model) => model.initData(),
                builder: (context, model, child) {
                  if (model.isBusy) {
                    return ViewStateBusyWidget();
                  } else if (model.isError) {
                    return ViewStateErrorWidget(
                        error: model.viewStateError, onPressed: model.initData);
                  } else if (model.isEmpty) {
                    return ViewStateEmptyWidget(onPressed: model.initData);
                  }
                  return SmartRefresher(
                      controller: model.refreshController,
                      header: WaterDropHeader(),
                      footer: RefresherFooter(),
                      onRefresh: model.refresh,
                      enablePullUp: true,
                      child: ListView.builder(
                          itemCount: model.list.length,
                          itemBuilder: (context, index) {
                            SalesCountItem item = model.list[index];
                            return SalesCountItemWidget(item);
                          }));
                },
              ),
            ),
          )
        ],
      ),
    );
  }
}
